package logicGame.States;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import javax.swing.JTextField;
import logicGame.*;

public class Setup extends StateAdapter {

    public Setup(Game g) {
        super(g);
    }

    @Override
    public State config(int nPlayers , ArrayList<JTextField> pNames) {
        //Shuffle Cards
        //Set 6 cards
        //Assign 14 armys to each player
        int i = 0;
        
        getGame().setnPlayers(nPlayers);
        
        int coins = 0;
        if (nPlayers == 5) {
            coins = 8;
        } else if (nPlayers == 4) {
            coins = 9;
        } else if (nPlayers == 3) {
            coins = 11;
        } else if (nPlayers == 2) {
            coins = 14;
        }
        
        //inicia IA
        for (; i < nPlayers-pNames.size(); i++) {
            String p = "IA " + (i + 1);
            getGame().addPlayer(p, coins, true);
            getGame().getPlayer(i).inicializeResources();
            for (int x = 0; x < 3; x++) {
                getGame().getBoard().placeArmy(getGame().getPlayer(i),0);
                getGame().getPlayer(i).removeTroop();
            }
        }
        
        for (i=0; i < pNames.size(); i++) {
            getGame().addPlayer(pNames.get(i).getText(), coins, false);
            getGame().getPlayer(i).inicializeResources();
            for (int x = 0; x < 3; x++) {
                getGame().getBoard().placeArmy(getGame().getPlayer(i),0);
                getGame().getPlayer(i).removeTroop();
            }
        }
        
        
        //inicialize cards
        getGame().inicializeDeck();
        getGame().initializeBoardDeck();

        getGame().setActivePlayer(getGame().getPlayer(0));
        return new Auction(getGame());
    }
}
